package net.factoryOpen.quickfactory.manufacturing.exe.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import net.factoryOpen.core.common.exception.StatusUnavailableException;
import net.factoryOpen.core.common.status.BillStatus;
import net.factoryOpen.quickfactory.manufacturing.exe.domain.ExeProcessWork;
import net.factoryOpen.quickfactory.manufacturing.exe.service.IExeProcessWorkService;
import net.factoryOpen.quickfactory.manufacturing.res.domain.ResMachine;
import net.factoryOpen.quickfactory.manufacturing.res.domain.ResWorkgroupMachine;
import net.factoryOpen.quickfactory.manufacturing.res.service.IResMachineService;
import net.factoryOpen.quickfactory.manufacturing.res.service.IResWorkgroupMachineService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import net.factoryOpen.quickfactory.manufacturing.exe.domain.ExeMlOperating;
import net.factoryOpen.quickfactory.manufacturing.exe.service.IExeMlOperatingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车间班组作业Controller
 *
 * @author factoryOpen
 * @date 2025-06-01
 * @version 1.0.0-draft.0
 */
@Service
@RestController
@RequestMapping("/exe/mlOperating")
public class ExeMlOperatingController extends BaseController
{
    @Autowired
    private IExeMlOperatingService exeMlOperatingService;

    @Autowired
    private IExeProcessWorkService exeProcessWorkService;

    @Autowired
    private IResWorkgroupMachineService resGroupMachineService;

    /**
     * 查询车间班组作业列表
     */
    //@PreAuthorize("@ss.hasPermi('exe:mlOperating:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExeMlOperating exeMlOperating)
    {
        startPage();
        List<ExeMlOperating> list = exeMlOperatingService.selectExeMlOperatingList(exeMlOperating);

        return getDataTable(list);
    }

    /**
     * 查询车间班组作业列表
     */
    //@PreAuthorize("@ss.hasPermi('exe:mlOperating:listByOperator')")
    @GetMapping("/listByOperator")
    public TableDataInfo listByOperator(ExeMlOperating exeMlOperating)
    {
        startPage();
        List<ExeMlOperating> list = exeMlOperatingService.selectExeMlOperatingListByOperator(exeMlOperating);

        return getDataTable(list);
    }

    /**
     * 导出车间班组作业列表
     */
    //@PreAuthorize("@ss.hasPermi('exe:mlOperating:export')")
    @Log(title = "车间班组作业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExeMlOperating exeMlOperating)
    {
        List<ExeMlOperating> list = exeMlOperatingService.selectExeMlOperatingList(exeMlOperating);
        ExcelUtil<ExeMlOperating> util = new ExcelUtil<ExeMlOperating>(ExeMlOperating.class);
        util.exportExcel(response, list, "车间班组作业数据");
    }

    /**
     * 获取车间班组作业详细信息
     */
    //@PreAuthorize("@ss.hasPermi('exe:mlOperating:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(exeMlOperatingService.selectExeMlOperatingById(id));
    }

    /**
     * 新增车间班组作业
     */
    //@PreAuthorize("@ss.hasPermi('exe:mlOperating:add')")
    @Log(title = "车间班组作业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExeMlOperating exeMlOperating)
    {
        AjaxResult ar = null;
        try{
           int ret = exeMlOperatingService.insertExeMlOperating(exeMlOperating);
           if (ret > 0){
               ar = AjaxResult.success("操作成功：[新增]1条数据！");
           }
           else{
               ar = AjaxResult.error(ret, "操作失败：[新增]0条数据！");
           }
        }
        catch (Exception e){
            e.printStackTrace();
            ar = AjaxResult.error("操作异常："+e.getMessage());
        }
        return ar;
    }

    /**
     * 修改车间班组作业
     */
    //@PreAuthorize("@ss.hasPermi('exe:mlOperating:edit')")
    @Log(title = "车间班组作业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExeMlOperating exeMlOperating)
    {
        AjaxResult ar = null;
        try{
            int ret = exeMlOperatingService.updateExeMlOperating(exeMlOperating);
            if (ret > 0){
                ar = AjaxResult.success("操作成功：[修改]"+ret+"条数据！");
            }
            else{
                ar = AjaxResult.error(ret, "操作失败：[修改]0条数据！");
            }
        }
        catch (Exception e){
            e.printStackTrace();
            ar = AjaxResult.error("操作异常："+e.getMessage());
        }
        return ar;
    }

    /**
     * 删除车间班组作业
     */
    //@PreAuthorize("@ss.hasPermi('exe:mlOperating:remove')")
    @Log(title = "车间班组作业", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        AjaxResult ar = null;
        try{
            int ret = exeMlOperatingService.deleteExeMlOperatingByIds(ids);
            if (ret > 0){
                ar = AjaxResult.success("操作成功：[删除]"+ret+"条数据！");
            }
            else{
                ar = AjaxResult.error(ret, "操作失败：[删除]0条数据！");
            }
        }
        catch (Exception e){
            e.printStackTrace();
            ar = AjaxResult.error("操作异常："+e.getMessage());
        }
        return ar;
    }

}
